#!/bin/bash

setenv() {
    local name=$1
    local value=$2
    
    # 设置当前会话的环境变量
    export $name=$value
    
    # 尝试添加到用户的shell配置文件中（持久化）
    local profile_file=""
    if [ -f "$HOME/.bashrc" ]; then
        profile_file="$HOME/.bashrc"
    elif [ -f "$HOME/.zshrc" ]; then
        profile_file="$HOME/.zshrc"
    fi
    
    if [ -n "$profile_file" ]; then
        echo "export $name=\"$value\"" >> "$profile_file"
        echo "Environment variable $name set to $value (added to $profile_file)"
    else
        echo "Environment variable $name set to $value (applies to current session only)"
    fi
}